package chalmers.edu.jacobla_anerud.MatematiskModelleringModul3;

import java.awt.Color;
import java.util.LinkedList;
import java.util.List;

public class Ball {
	private double x, y, vx, vy, weight, pixelsPerMeter;
	private int radius;
	Color color;
	private List<Ball> inHitWith;
	
	public Ball(double x, double y, double vx, double vy, int radius, double pixelsPerMeter,Color color){
		this.x=x;
		this.y=y;
		this.vx=vx;
		this.vy=vy;
		this.radius=radius;
		this.weight=radius*radius;
		this.pixelsPerMeter=pixelsPerMeter;
		this.color=color;
		inHitWith = new LinkedList<Ball>();
	}
	public Color getColor() {
		return color;
	}
	public double getX() {
		return x;
	}
	public void setX(double x) {
		this.x = x;
	}
	public double getY() {
		return y;
	}
	public void setY(double y) {
		this.y = y;
	}
	public double getVx() {
		return vx;
	}
	public void setVx(double vx) {
		this.vx = vx;
	}
	public double getVy() {
		return vy;
	}
	public void setVy(double vy) {
		this.vy = vy;
	}
	public int getRadius() {
		return radius;
	}
	public double getWeight() {
		return weight;
	}
	public double getPixelsPerMeter() {
		return pixelsPerMeter;
	}
	public int getPixelX() {
		return (int)(x*pixelsPerMeter);
	}
	public int getPixelY() {
		return (int)(y*pixelsPerMeter);
	}
	public void addInHitWith(Ball b){
		inHitWith.add(b);
	}
	public void removeInHitWith(Ball b){
		inHitWith.remove(b);
	}
	
	public Boolean isInHitWith(Ball b){
		return inHitWith.contains(b);
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((color == null) ? 0 : color.hashCode());
		long temp;
		temp = Double.doubleToLongBits(pixelsPerMeter);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result + radius;
		temp = Double.doubleToLongBits(vx);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		temp = Double.doubleToLongBits(vy);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		temp = Double.doubleToLongBits(weight);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		temp = Double.doubleToLongBits(x);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		temp = Double.doubleToLongBits(y);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Ball other = (Ball) obj;
		if (color == null) {
			if (other.color != null)
				return false;
		} else if (!color.equals(other.color))
			return false;
		if (Double.doubleToLongBits(pixelsPerMeter) != Double
				.doubleToLongBits(other.pixelsPerMeter))
			return false;
		if (radius != other.radius)
			return false;
		if (Double.doubleToLongBits(vx) != Double.doubleToLongBits(other.vx))
			return false;
		if (Double.doubleToLongBits(vy) != Double.doubleToLongBits(other.vy))
			return false;
		if (Double.doubleToLongBits(weight) != Double
				.doubleToLongBits(other.weight))
			return false;
		if (Double.doubleToLongBits(x) != Double.doubleToLongBits(other.x))
			return false;
		if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y))
			return false;
		return true;
	}
	
	
}
